#include"taskbar.h"
#include<sys/walltime.h>
#include<stdio.h>
#include<gui.h>

bool timer_func(gui_spirit_t *window,uint32_t id,void *data)
{
    walltime_t wtm;
    walltime(&wtm); 
    char buff[32]={0};

    sprintf(buff,"%d/%d/%d %d:%d:%d",wtm.year,wtm.month,wtm.day,wtm.hour,wtm.minute,wtm.second);
    gui_spirit_t *label=(gui_spirit_t*)data;
    gui_label_set_text(label,buff,strlen(buff));
    gui_spirit_show(label);
    return true;
}

int taskbar_clock_init(gui_spirit_t *spirit)
{
    walltime_t wtm;
    walltime(&wtm);
    char buff[32]={0};
    sprintf(buff,"%d/%d/%d %d:%d:%d",(uint32_t)wtm.year,(uint32_t)wtm.month,(uint32_t)wtm.day,(uint32_t)wtm.hour,(uint32_t)wtm.minute,(uint32_t)wtm.second);
    gui_spirit_t *clock_label=gui_label_create(buff);
    gui_spirit_set_pos(clock_label,taskbar.spirit->width-((strlen(buff)*8+5)),taskbar.spirit->height/2-16/2);
    gui_container_add(GUI_CONTAINER(spirit),clock_label);

    clock_label->style.font_color=GUI_WHITE;
    clock_label->style.background_color=taskbar.taskbar_color;
    taskbar.clock_label=clock_label;
    gui_window_add_timer(GUI_WINDOW(spirit),1000,timer_func,clock_label);

    return 0;
}